package com.cyzy.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cyzy.dao.AttendStudentClassDao;
import com.cyzy.dao.StudentCourseDao;
import com.cyzy.mapper.StudentMapper;
import com.cyzy.pojo.Attend;
import com.cyzy.pojo.Student;
import com.cyzy.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Autowired
    private StudentMapper studentMapper;

    @Override
    public int disabledStudent(Integer id) {
        LambdaUpdateWrapper<Student> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.set(Student::getStudentStatus, 1).eq(Student::getStudentId, id);
        return studentMapper.update(updateWrapper);
    }

    @Override
    public Page<StudentCourseDao> selectStudents(StudentCourseDao studentCourseDao) {
        Page<StudentCourseDao> page = new Page<>(studentCourseDao.getPageNum(), studentCourseDao.getPageSize());
        return studentMapper.selectStudentsCampusId(page, studentCourseDao,studentCourseDao.getStudentName(),studentCourseDao.getCourseId());
    }

    @Override
    public List<StudentCourseDao> selectAllStudent(StudentCourseDao studentCourseDao) {
        return studentMapper.selectAllStudents(studentCourseDao);
    }

    @Override
    public Page<AttendStudentClassDao> attend(AttendStudentClassDao attendStudentClassDao) {
        Page<AttendStudentClassDao> page = new Page<>(attendStudentClassDao.getPageNum(), attendStudentClassDao.getPageSize());
        return studentMapper.attend(page,attendStudentClassDao,attendStudentClassDao.getClassId(),attendStudentClassDao.getAttendDate());
    }

    @Override
    public int addAttend(Attend attend) {

        System.out.println(attend + "-----------------");
        return studentMapper.addAtend(attend);
    }

    @Override
    public int AddStudent(Student student) {
        return studentMapper.addStudent(student);
    }

    @Override
    public int resetPwd(Student student) {
        return studentMapper.resetPwd(student);
    }

    @Override
    public int deleteStudent(Student student) {
        return studentMapper.deleteStudent(student);
    }
}
